import re

pat = r'(?P<first>\w+) (?P<last>\w+)'
s = 'Jane Austen'
m = re.match(pat,s)

print('first name=',m.group('first'))
print('first name=',m.group('last'))

# re.split 函数
patt = r', *| +'
lst = re.split(patt,'3, 5  7 8,10, 11')
print(lst)


# Scanner类
def sc_oper(scanner,tok):return tok
def sc_int(scanner,tok):return int(tok)
def sc_float(scanner,tok):return float(tok)
scanner = re.Scanner([
    (r'[*+/-]',sc_oper),
    (r'\d+\.\d*',sc_float),  # 将浮点模式放在整数模式前很重要 比如 11.502 会被读取成整数 11
    (r'\d+',sc_int),
    (r'\s+',None)
])
print(scanner.scan('3 3+'))




